package com.group525.cloudef.controller.admin;

import com.group525.cloudef.common.CommonResult;
import com.group525.cloudef.entity.admin.User;
import com.group525.cloudef.entity.doctor.DUser;
import com.group525.cloudef.entity.user.UUser;
import com.group525.cloudef.service.user.UUserService;
import com.group525.cloudef.utils.Log;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import  com.group525.cloudef.service.admin.userService;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("/admin/user")
@CrossOrigin
@Slf4j
@Api(tags = "用户管理")
public class UserController {

    @Resource
    userService userService;

    @Resource
    UUserService uuserService;

    @Resource
    Log logger;
    @PostMapping("/login")
    @ApiOperation(value = "用户登录")
    public CommonResult<?> login(@RequestBody User user){

        logger.debug("user:",user);

        return userService.login(user);
    }

    @GetMapping("/getUsers")
    @ApiOperation(value = "获取患者用户")
    public List<?>getUsers(){
        return uuserService.list();
    }


    @DeleteMapping("/deleteUserById/{id}")
    public CommonResult<?> deleteUserById(@PathVariable String id){
        if(uuserService.removeById(id)){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @PostMapping("/editUser")
    @ApiOperation(value = "编辑患者")
    public CommonResult<?> editUser(@RequestBody UUser user){
        log.debug("编辑的患者信息：",user);
        if (uuserService.updateById(user)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @PostMapping("/editAdmin")
    @ApiOperation(value = "编辑管理员")
    public CommonResult<?> editUser(@RequestBody User user){
        log.debug("编辑的管理员信息：",user);
        if (userService.updateById(user)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

}
